const connection = require('../app/database')

class UserService {
  async create(user) {
    const {username, password} = user
    const statement = `insert into users (username, password) values (?, ?);`  
    const result = await connection.execute(statement, [username, password])

    return result
  }

  async getUserByName(username) {
    const statement =  `select * from users where username = ?;`
    const result = await connection.execute(statement, [username])
    
    return result[0]
  }

  async initUserinfo(name, id) {
    const statement = `insert into userinfo (name, user_id) values (?, ?)`
    const [result] = await connection.execute(statement, [name, id])
    return result
  }
}

module.exports = new UserService()